#ifndef __MY_LIST_H__
#define __MY_LIST_H__

#include <stddef.h>
#include "type.h"

//-------------------------------------------------
typedef struct list_node
{
	struct list_node *next;
	struct list_node *prev;
} list_node_t;

typedef struct list_t
{
	list_node_t head;
	list_node_t tail;
} list_t;

#define entry_list(LIST_NODE, STRUCT, MEMBER)((STRUCT *)((unsigned char *)&(LIST_NODE)->next-offsetof(STRUCT, MEMBER.next)))

void 	list_init(list_t *plist);

list_node_t *list_front(list_t *plist);
list_node_t *list_back(list_t *plist);

list_node_t *list_begin(list_t *plist);
list_node_t *list_next(list_node_t *pnode);
list_node_t *list_end(list_t *plist);

void list_insert_before(list_node_t *after, list_node_t *pnode);
void list_insert_after(list_node_t *before, list_node_t *pnode);
void list_insert_front(list_t *plist, list_node_t *pnode);
void list_insert_back(list_t *plist, list_node_t *pnode);

list_node_t *list_delete(list_node_t *pnode);
list_node_t *list_delete_front(list_t *plist);
list_node_t *list_delete_back(list_t *plist);

u16	list_get_count(list_t* plist);

#endif

